package tomcat;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 简易客户端 向服务器发送请求
 */
public class TestClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 8888);
        OutputStream output = socket.getOutputStream();
        // 模拟客户端 发送请求
        output.write("GET /index.html HTTP/1.1".getBytes());
        socket.shutdownOutput();

        InputStream inputStream = socket.getInputStream();
        byte[] buffer = new byte[12048];
        int length = inputStream.read(buffer);
        System.out.println(length);
        StringBuilder response = new StringBuilder();
        for (int j = 0;j < length; j++) {
            response.append((char)buffer[j]);
        }

        System.out.println(response.toString());
        socket.shutdownInput();
        socket.close();
    }

}
